//
//  YWTakePhotoCell.m
//  maintain
//
//  Created by 烟雨云渊 on 16/8/9.
//  Copyright © 2016年 ewin. All rights reserved.
//

#import "YWTakePhotoCell.h"
#import "Masonry.h"
#import "YWMacro.h"
#import "YWPhotoView.h"

#import "YWEquipment.h"

@interface YWTakePhotoCell()<YWPhotoViewDelegate>
@property (nonatomic, strong) YWPhotoView* imageV;
@end

@implementation YWTakePhotoCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self setUpSubviews];
    }
    return self;
}

-(YWPhotoView *)imageV{
    if (!_imageV) {
        YWPhotoView* imageV = [[YWPhotoView alloc] init];
        imageV.delegate = self;
        [self.contentView addSubview:imageV];
        _imageV = imageV;
    }
    return _imageV;
}

- (void)setTotalImageNameArray:(NSArray *)totalImageNameArray{
    _totalImageNameArray = totalImageNameArray;
    self.imageV.photosArray = totalImageNameArray;
    [self.imageV layoutSubviews];
}

- (void)setCanAddPhoto:(BOOL)canAddPhoto{
    _canAddPhoto = canAddPhoto;
    self.imageV.canAddPhoto = canAddPhoto;
}

- (void)setPickFromPhotoLibrary:(BOOL)pickFromPhotoLibrary{
    _pickFromPhotoLibrary = pickFromPhotoLibrary;
    self.imageV.pickFromPhotoLibrary = pickFromPhotoLibrary;
}

#pragma mark - YWPhotoViewDelegate
- (void)resetPhotoViewFrame:(CGRect)rect andTotalPhotoArray:(NSArray *)photoNameArray{
    if ([self.delegate respondsToSelector:@selector(resetCellFrameWithImages:cell:)]) {
        [self.delegate resetCellFrameWithImages:photoNameArray cell:self];
    }
}

- (void)setUpSubviews{
    [self.imageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView).insets(UIEdgeInsetsMake(10, 0, 10, 0));
    }];
}

@end
